﻿<UserControl x:Class="MOCSoftware.Utilities.PortInspector.View.PortListView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             xmlns:Properties="clr-namespace:MOCSoftware.Utilities.PortInspector.Properties"
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="..\\ApplicationResources.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="50" />
            <RowDefinition Height="50" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Label
            Grid.Row="0"
            Target="{Binding ElementName=txtPortFilter}"
            Content="{x:Static Properties:Resources.PortListView_PortFilterLabel}" />
        <TextBox
            Grid.Row="0"
                Name="txtPortFilter"
            Style="{StaticResource InputControlStyle}"
            Text="{Binding Path=PortFilter, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}" />
        <Label
            Grid.Row="1" 
            Target="{Binding ElementName=ddlProtocol}" Content="{x:Static Properties:Resources.PortListView_ProtocolLabel}" />
        <ComboBox
            Name="ddlProtocol"
            Grid.Row="1"
            Style="{StaticResource InputControlStyle}"
            ItemsSource="{Binding Path=ProtocolList}"
            SelectedValue="{Binding Path=SelectedProtocol,Mode=OneWayToSource}" />
        <Label
            Grid.Row="2" 
            Target="{Binding ElementName=grdPorts}" Content="{x:Static Properties:Resources.PortListView_PortsLabel}" />
        <ListBox Name="lstPorts" ItemsSource="{Binding Path=PortList}" Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,25,0,0" ItemTemplate="{StaticResource PortList}" SelectedItem="{Binding Path=SelectedPort, Mode=TwoWay}">
            <ListBox.ContextMenu>
                <ContextMenu ItemsSource="{Binding MenuItems}" ItemTemplate="{StaticResource ContextMenuTemplate}">
                </ContextMenu>
            </ListBox.ContextMenu>
            <ListBox.ItemContainerStyle>
                <Style>
                    <Style.Resources>
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
                        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
                    </Style.Resources>
                </Style>
            </ListBox.ItemContainerStyle>
            <ListBox.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
            </ListBox.Resources>
        </ListBox>
        <DataGrid Visibility="Hidden"
            Grid.Row="2"
            Style="{StaticResource PortGridStyle}"
                  ItemsSource="{Binding Path=PortList}" Name="grdPorts" AutoGenerateColumns="False" GridLinesVisibility="None"
                      SelectionMode="Single" SelectionUnit="FullRow">
            <DataGrid.Columns>
                <DataGridCheckBoxColumn IsThreeState="False" Binding="{Binding IsSelected, Mode=TwoWay}" />
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding PortName}" Header="Name" />
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding PortNumber}" Header="#" />
                <DataGridTextColumn IsReadOnly="True" Binding="{Binding Protocol}" Header="Protocol" />
            </DataGrid.Columns>
            <DataGrid.RowStyle>
                <Style TargetType="DataGridRow">
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="Blue" />
                        </Trigger>
                    </Style.Triggers>
                    <EventSetter Event="MouseEnter" Handler="OnPortListRowMouseEnter"  />
                    <EventSetter Event="MouseLeave" Handler="OnPortListRowMouseLeave" />
                </Style>
            </DataGrid.RowStyle>
            <DataGrid.ContextMenu>
                <ContextMenu ItemsSource="{Binding MenuItems}" ItemTemplate="{StaticResource ContextMenuTemplate}">
                </ContextMenu>
            </DataGrid.ContextMenu>
        </DataGrid>
    </Grid>
</UserControl>